#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    char*const env[]={
        (char*)"haha=hehe",
        (char*)"PATH=/",
        NULL
    };

    printf("I am a process, pid: %d\n", getpid());
    
    pid_t id = fork();
    if (id == 0)
    {
        extern char **environ;
        sleep(1);
        execle("./mytest","mytest",NULL,environ);
        // execle("./mytest","mytest",NULL,env);
        // execl("./mytest","mytest",NULL);
        // char *const argv[] = {
        //     (char *)"ls",
        //     (char *)"-a",
        //     (char *)"-l"};
        // execv("/usr/bin/ls",argv);//p-自动搜索环境变量
        // execvp("ls", argv);//参数用数组
        // execlp("ls", "ls", "-a", "-l", NULL);//参数采用列表
        printf("exec end ...\n");//该代码没执行
        exit(1);
    }
    pid_t rid = waitpid(id, NULL, 0);
    if (rid > 0)
    {
        printf("wait successfully\n");
    }
    return 0;
}